/**
 * 
 */
package systole.view.crud.tableModels;

import java.util.List;

import systole.domain.clinicalInformation.Family;
import systole.domain.clinicalInformation.FamilyPatientBackground;

/**
 * @author jmj
 * 
 */
public class FamilyBackgroundTableModel extends SystoleTableModel<FamilyPatientBackground> {

    private String[] columnNames = {"Familiar", "Cardíados", "Diabéticos",
        "Colesterol", "Hipertensión"};
    private static final int FAMILY_INDEX = 0;
    private static final int CARDIAC_INDEX = 1;
    private static final int DIABETIC_INDEX = 2;
    private static final int CHORESTEROL_INDEX = 3;
    private static final int HYPERTENSION_INDEX = 4;

    /**
     * @param background
     *
     */
    public FamilyBackgroundTableModel(List<FamilyPatientBackground> background) {
        super(background);
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.swing.table.TableModel#getColumnClass(int)
     */
    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case FAMILY_INDEX:
                return Family.class;
            case CARDIAC_INDEX:
                return String.class;
            case DIABETIC_INDEX:
                return String.class;
            case CHORESTEROL_INDEX:
                return String.class;
            case HYPERTENSION_INDEX:
                return String.class;
        }
        return null;
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.swing.table.TableModel#getColumnCount()
     */
    @Override
    public int getColumnCount() {
        return this.columnNames.length;
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.swing.table.TableModel#getColumnName(int)
     */
    @Override
    public String getColumnName(int columnIndex) {
        return this.columnNames[columnIndex];
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.swing.table.TableModel#getValueAt(int, int)
     */
    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case FAMILY_INDEX:
                return this.entities.get(rowIndex).getFamily();
            case CARDIAC_INDEX:
                boolean cardiac = (this.entities.get(rowIndex).getBackgroundCardiac() ? this.entities.get(rowIndex).getBackgroundCardiac().booleanValue() : false);
                return (cardiac ? "Si" : "No");
            case DIABETIC_INDEX:
                boolean diabetic = (this.entities.get(rowIndex).getBackgroundDiabetic() ? this.entities.get(rowIndex).getBackgroundDiabetic().booleanValue() : false);
                return (diabetic ? "Si" : "No");
            case CHORESTEROL_INDEX:
                boolean chresterol = (this.entities.get(rowIndex).getBackgroundCholesterol() ? this.entities.get(rowIndex).getBackgroundCholesterol().booleanValue() : false);
                return (chresterol ? "Si" : "No");
            case HYPERTENSION_INDEX:
                boolean hypertension = (this.entities.get(rowIndex).getBackgroundHypertension() ? this.entities.get(rowIndex).getBackgroundHypertension().booleanValue() : false);
                return (hypertension ? "Si" : "No");
        }
        return null;
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
     */
    @Override
    public void setValueAt(Object arg0, int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case FAMILY_INDEX:
                this.entities.get(rowIndex).setFamily((Family) arg0);
                break;
            case CARDIAC_INDEX:
                boolean cardiac = "Si".equals(arg0);
                this.entities.get(rowIndex).setBackgroundCardiac(cardiac);
                break;
            case DIABETIC_INDEX:
                boolean diabetic = "Si".equals(arg0);
                this.entities.get(rowIndex).setBackgroundDiabetic(diabetic);
                break;
            case CHORESTEROL_INDEX:
                boolean chresterol = "Si".equals(arg0);
                this.entities.get(rowIndex).setBackgroundCholesterol(chresterol);
                break;
            case HYPERTENSION_INDEX:
                boolean hypertension = "Si".equals(arg0);
                this.entities.get(rowIndex).setBackgroundHypertension(hypertension);
                break;
        }

    }
}
